﻿<script type="text/javascript">
    var toolbar_gongyingshang = [{
        text: '新增供应商',
        iconCls: 'icon-add',
        handler: function () {
            $("#gongyingshang-edit").dialog('open');
            $("#gongyingshangid").val('');
            $("#info-gongyingshangmingcheng").textbox('setValue', '');
            $("#info-gongyingshangzhuangtai").combobox('setValue', '启用');
        }
    }, '-', {
        text: '修改供应商',
        iconCls: 'icon-edit',
        handler: function () {
            var curRow = $("#xinxi_gongyingshang").datagrid('getSelected');
            if (curRow) {
                $("#gongyingshangid").val(curRow.id);
                $("#gongyingshang-edit").dialog('open');
                $("#info-gongyingshangmingcheng").textbox('setValue', curRow.mingcheng);
                if (curRow.zhuangtai == "启用") {
                    $("#info-gongyingshangzhuangtai").combobox('setValue', '启用');
                }
                else {
                    $("#info-gongyingshangzhuangtai").combobox('setValue', '禁用');
                }
            }
            else {
                alert("请选择要修改的供应商信息。");
            }
        }
    }, '-', {
        text: '删除供应商',
        iconCls: 'icon-remove',
        handler: function () {
            $("#gongyingshang-dlg").dialog('open');
        }
    }];

    function DelGongYingShang() {
        var curRow = $("#xinxi_gongyingshang").datagrid('getSelected');
        if (curRow) {
            $.post('handler/xinxi_gongyingshang.ashx', { gongYingShangType: "3", gongyingshangid: curRow.id, uid: window.uid, kid: window.kid }, function (data, status) {
                if (data == "OK") {
                    $("#gongyingshang-dlg").dialog('close');
                    $("#xinxi_gongyingshang").datagrid('load');
                    return;
                }
                if (data == "Failed") {
                    alert("删除供应商信息失败，请重试");
                    $("#gongyingshang-dlg").dialog('close');
                    return;
                }
                alert(data);
                $("#gongyingshang-dlg").dialog('close');
            });
        }
        else {
            alert("请选择要删除的供应商信息。");
        }

    }

    function submitGongYingShang() {
        var gongyingshangmingcheng = $("#info-gongyingshangmingcheng").textbox('getText');
        var gongyingshangzhuangtai = $("#info-gongyingshangzhuangtai").combobox('getText');
        var gongyingshangid = $("#gongyingshangid").val();
        if (gongyingshangmingcheng && gongyingshangzhuangtai) {
            $.post("handler/xinxi_gongyingshang.ashx", { uid: window.uid, kid: window.kid, gongyingshangid: gongyingshangid, gongYingShangType: '2', gongyingshangmingcheng: gongyingshangmingcheng, gongyingshangzhuangtai: gongyingshangzhuangtai }, function (data, status) {
                if (data == "OK") {
                    $("#gongyingshang-edit").dialog('close');
                    $("#xinxi_gongyingshang").datagrid('load');
                    return;
                }
                if (data == "Failed") {
                    alert("保存供应商信息失败，请重试");
                    return;
                }
                alert(data);
            });
        }
        else {
            alert("信息不完整，请检查后重试。");
        }

    }

    function clearGongYingShangForm() {
        $("#gongyingshang-edit").dialog('close');
    }
    $.parser.onComplete = function () {
        $("#xinxi_gongyingshang").datagrid({
            url: 'handler/xinxi_gongyingshang.ashx',
            method: 'post',
            queryParams: { gongYingShangType: '1', uid: window.uid, kid: window.kid }
        });
    }
</script>

<table id="xinxi_gongyingshang" style="width:100%" class="easyui-datagrid" title="供应商管理" data-options="border:false,singleSelect:true,collapsible:false,striped:true,toolbar:toolbar_gongyingshang">
    <thead>
        <tr>
            <th data-options="field:'mingcheng',width:200">
                供应商名称
            </th>
            <th data-options="field:'zhuangtai',width:100">
                状态
            </th>
            <th data-options="field:'id',hidden:true">
                编号
            </th>
        </tr>
    </thead>
</table>


<div id="gongyingshang-edit" class="easyui-dialog" title="供应商信息编辑" data-options="modal:true,closed:true,iconCls:'icon-edit',draggable:false,collapsible:false,minimizable:false,maximizable:false,resizable:false"
     style="width: 500px; height: 220px; padding: 10px;">
    <div style="width: 350px; margin: 0 auto;">
        <table cellpadding="5" style="font-size: 13px; margin: 0 auto; padding-top: 20px">
            <tr>
                <td>
                    供应商名称:
                </td>
                <td>
                    <input class="easyui-textbox" type="text" id="info-gongyingshangmingcheng" name="info-gongyingshangmingcheng"
                           data-options="width:200"></input>
                </td>
            </tr>
            <tr>
                <td>
                    状态:
                </td>
                <td>
                    <select class="easyui-combobox" name="info-gongyingshangzhuangtai" id="info-gongyingshangzhuangtai"
                            data-options="width:200, panelHeight: 'auto',editable:false">
                        <option value="启用">启用</option>
                        <option value="禁用">禁用</option>
                    </select>
                </td>
            </tr>
        </table>
        <input type="hidden" name="gongyingshangid" id="gongyingshangid" value="" />
        <div style="text-align: center; padding: 5px">
            <a href="javascript:void(0)" class="easyui-linkbutton" style="width: 75px" onclick="submitGongYingShang()" data-options="iconCls:'icon-ok'">保存</a>
            <a href="javascript:void(0)" class="easyui-linkbutton" style="width: 75px" onclick="clearGongYingShangForm()" data-options="iconCls:'icon-cancel'">关闭</a>
        </div>
    </div>
</div>


<div id="gongyingshang-dlg" class="easyui-dialog" title="删除确认" style="width: 300px; height: 150px;
    padding: 10px" data-options="iconCls: 'icon-help',buttons: '#gongyingshang-dlg-buttons',modal:true,closed:true">
    确定要删除该单位信息吗？
</div>
<div id="gongyingshang-dlg-buttons">
    <a href="javascript:void(0)" class="easyui-linkbutton" onclick="javascript: DelGongYingShang();">
        确定
    </a>
    <a href="javascript:void(0)" class="easyui-linkbutton" onclick="javascript: $('#gongyingshang-dlg').dialog('close');">
        取消
    </a>
</div>


